<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="./js/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
    <div id="app">
        <div>
            用户名：<input type="text" v-model="username">
        </div>
        <div>
            密码：<input type="text" v-model="password">
        </div>
        <div>
            <button @click="login">登录</button>
        </div>
    </div>
    <script>
        new Vue({
            el: "#app",
            data() {
                return {
                    username: null,
                    password: null
                }
            },
            methods: {
                login() {
                    //发送Ajax请求
                    axios.post('http://vue.ruoyi.vip/prod-api/login',{username:this.username,password:this.password})
                    .then( res=> {
                        let data=res.data;
                        //请求成功后的回调函数
                        console.log(data);
                        if(data.code !=200){
                            alert(data.msg)
                        }
                    }).catch( error => {
                        //请求发生错误后回调的函数
                        console.log(error)
                    })
                }
            },
        })
    </script>
</body>

</html>